﻿using DemoUser.Application.User.Dtos;
using DemoUser.Application.User.Filter;
using DemoUser.Application.User.Interface;
using DemoUser.Core.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoUser.Application.User.Services
{
    //[Injection(Proxy = typeof(LogDispatchProxy))]
    public class BrandService : IBrandService, ITransient
    {
        private readonly ISqlSugarClient _client;

        public BrandService(ISqlSugarClient client)
        {
            _client = client;
        }

        public List<Model> GroupByStatus()
        {
            List<Model> result = new List<Model>();
            
            return _client.Queryable<Brand>().ToList().GroupBy(b => b.Status).Select(x => new Model
            {
                Status = x.Key,
                brands = x.ToList<Brand>()
            }).ToList();
        }

        public List<Brand> SelectAll()
        {
            return _client.Queryable<Brand>().ToList();
        }

        public Brand SelectById(int id)
        {
            List<Brand> brands = _client.Queryable<Brand>().Where(b => b.Id == id).ToList();
            Brand brand = new Brand();
            for (int i = 0;i<brands.Count;i++)
            {
                brand = brands[i];
            }
            return brand;
        }
    }
}
